# -*- coding: utf-8 -*-
"""
 @Time    : 2021/2/5 下午4:28
 @Author  : tgy
 
"""
import threading
import time

datas = []

def run01(name, age):
    ...
    # print(name, age)
    for i in range(10):
        datas.append(i)
        time.sleep(0.5)

def test01():
    ...
    thread = threading.Thread(target=run01,args=('tony',),kwargs={'age':100})
    thread.setDaemon(True)
    thread.start()

    # while thread.is_alive():
    #     ...
    #     print(datas)
    #     time.sleep(1)
    thread.join()


sum = 0



def run02(lock:threading.Lock):
    ...
    global sum
    for i in range(100000):
        try:
            lock.acquire()
            sum += 1
        finally:
            lock.release()

def run03(lock:threading.Lock):
    ...
    global sum
    for i in range(100000):
        try:
            lock.acquire()
            sum += 1
        finally:
            lock.release()


def test02():
    ...
    lock = threading.RLock()
    t1 = threading.Thread(target=run02, args=(lock,))
    t2 = threading.Thread(target=run03, args=(lock,))
    t1.start()
    t2.start()
    while threading.active_count() != 1:
        ...
        time.sleep(0.1)
    print(sum)


if __name__ == '__main__':
    ...
    test02()